<?php 
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

$option = JRequest::getCmd('option');

JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
jimport( 'joomla.html.editor' );

$editor = JFactory::getEditor();
$items = JRequest::getVar('items');
$link = JRoute::_('index.php?option=' . $option . '&view=billout');
?>

<script>

  window.addEvent('domready', function(){
	$('#toolbar-cancel').click(function(){
		//window.history.back()
	});
  });
</script>

<form action="<?php echo $link ?>" method="post" name="adminForm"
	id="fee-admin-form" class="form-validate">
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input
		type="hidden" name="task" value="" />
		<input type="hidden" name="id"
		value="<?php echo $this->item->id; ?>" />
	<?php echo JHtml::_('form.token'); ?>

	<fieldset class="adminform">
		<legend>
			<?php echo JText::_('COM_SHIPNHANH_COMPOSE_EMAIL'); ?>
		</legend>
		<ul class="adminformlist">
			<li>
				<label for="email_to"><?php echo JText::_('COM_SHIPNHANH_EMAIL_TO'); ?></label>
				
				<?php
					$useremail = JRequest::getVar('prepaidemail');
					
					if (!isset($useremail) || strlen($useremail) == 0)
						$useremail = JRequest::getVar('useremail');
				?>
				
				<input type="text" name="email_to" id="email_to" size="100" value="<?php echo JText::_($useremail); ?>" />
			</li>
			
			<li>
				<label for="email_subject"><?php echo JText::_('COM_SHIPNHANH_EMAIL_SUBJECT'); ?></label>
				<input type="text" name="email_subject" id="email_subject" size="100" value="<?php echo JText::_('COM_SHIPNHANH_EMAIL_SUBJECT_PREFIX'); ?>" />
			</li>
			
			<li>
				<label for="email_content"><?php echo JText::_('COM_SHIPNHANH_EMAIL_CONTENT'); ?></label>
			</li>
			
			<li>
			
			<?php
				$body = "<table border='1'>";
				$body .= JText::_('COM_SHIPNHANH_EMAIL_BODY_TABLE_HEADER');
				
				foreach ($items as $item)
				{
				?>
					<input type='checkbox' hidden='hidden' name='cid[]' value='<?php echo $item->id ?>' checked='checked' />
				<?php
					$body .= "<tr>";
					$body .= '<td>' . $item->orderdate . '</td>';
					$body .= '<td>' . $item->productname . '</td>';
					$body .= '<td>' . $item->webname . '</td>';
					$body .= '<td>' . $item->color . '</td>';
					$body .= '<td>' . $item->size . '</td>';
					$body .= '<td>' . $item->quantity . '</td>';
					$body .= '<td>' . number_format($item->usprice, 2) . '</td>';
					$body .= '<td>' . number_format($item->tax, 2) . '</td>';
					$body .= '<td>' . number_format($item->shipus, 2) . '</td>';
					$body .= '<td>' . number_format($item->webcharge, 2) . '</td>';
					$body .= '<td>' . number_format($item->surcharge, 2) . '</td>';
					$body .= "</tr>";
				}
				
				$body .= "</table>";
				
				$body .= '<p>' . JText::_('COM_SHIPNHANH_SHIPNHANH_WEBCHARGE_TOTAL') . ': ';
				$body .= number_format(JRequest::getVar('webchargeTotal', '0', 'post', 'INT'), 2) . '</p>';
				
				$body .= '<p>' . JText::_('COM_SHIPNHANH_SHIPNHANH_SHIP_USVN_TOTAL') . ': ';
				$body .= number_format(JRequest::getVar('shippingtotal', '0', 'post', 'INT'), 2) . '</p>';
				
				$body .= '<p>' . JText::_('COM_SHIPNHANH_SHIPNHANH_SHIP_FEE_TOTAL') . ': ';
				$body .= number_format(JRequest::getVar('shipfee', '0', 'post', 'INT'), 2) . '</p>';
				
				$body .= '<p>' . JText::_('COM_SHIPNHANH_SHIPNHANH_SURCHARGE_TOTAL') . ': ';
				$body .= number_format(JRequest::getVar('surchargeTotal', '0', 'post', 'INT'), 2) . '</p>';
				
				$body .= '<p>' . JText::_('COM_SHIPNHANH_SHIPNHANH_TOTAL_WITH_SHIP') . ': ';
				$body .= number_format(JRequest::getVar('total', '0', 'post', 'INT'), 2) . '</p>';
				
				$body .= '<p>' . JText::_('COM_SHIPNHANH_SHIPNHANH_TO_VND') . ': ';
				$body .= number_format(JRequest::getVar('vndprice', '0', 'post', 'INT'), 2) . '</p>';
				
				$body .= '<p>' . JText::_('COM_SHIPNHANH_SHIPNHANH_PREPAID_VND') . ': ';
				$body .= number_format(JRequest::getVar('prepaid', '0', 'post', 'INT'), 2) . '</p>';
				
				$body .= '<p>' . JText::_('COM_SHIPNHANH_SHIPNHANH_REMAIN') . ': ';
				$body .= number_format(JRequest::getVar('remain', '0', 'post', 'INT'), 2) . '</p>';
			?>
			</li>
		</ul>
		
	</fieldset>
	
	<textarea cols="20" id="email_content" name="email_content" rows="20" ><?php echo $body ?></textarea>
				<script type="text/javascript">
							//<![CDATA[
					
								// Replace the <textarea id="editor"> with an CKEditor
								// instance, using default configurations.
								CKEDITOR.replace( 'email_content',
									{
										toolbar :
										[
											[ 'Format', 'Font','FontSize', 'Strike', 'Underline', 'Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink', 
											'-', 'TextColor', '-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl', 'Image']
										]
									});
					
							//]]>
							</script>
	
</form>
